package cn.maszy.service.impl.contract;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.contract.B_T_Ufp_PaymentMapper;
import cn.maszy.model.contract.B_T_Ufp_Payment;
import cn.maszy.model.contract.B_T_Ufp_PaymentExample;
import cn.maszy.service.contract.B_T_Ufp_PaymentService;

@Service
public class B_T_Ufp_PaymentServiceImpl implements B_T_Ufp_PaymentService{
	@Autowired
	private B_T_Ufp_PaymentMapper b_T_Ufp_PaymentMapper;
	public int update(B_T_Ufp_Payment b_T_Ufp_Payment,String uuid) {
		 if(b_T_Ufp_Payment.getUuid()==null||"".equals(b_T_Ufp_Payment.getUuid())){
			 b_T_Ufp_Payment.setUuid(UUID.randomUUID().toString());
			 b_T_Ufp_Payment.setSerialnumber(uuid);
			 b_T_Ufp_Payment.setIsDelete(0);
			 b_T_Ufp_Payment.setCreateTime(new Date());
			 b_T_Ufp_Payment.setCreateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_PaymentMapper.insert(b_T_Ufp_Payment);
		 }else{
			 b_T_Ufp_Payment.setUpdateTime(new Date());
			 b_T_Ufp_Payment.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_PaymentMapper.updateByPrimaryKeySelective(b_T_Ufp_Payment);
		 }
	}

	public B_T_Ufp_Payment selectOne(String uuid) {
		B_T_Ufp_Payment record=b_T_Ufp_PaymentMapper.selectByPrimaryKey(uuid);
		return record;
	}

	public Pager<B_T_Ufp_Payment> selectOnepay(String uuid,Pager<B_T_Ufp_Payment> pager) {
		B_T_Ufp_PaymentExample example=new B_T_Ufp_PaymentExample();
		cn.maszy.model.contract.B_T_Ufp_PaymentExample.Criteria criteria = example.createCriteria();
		criteria.andSerialnumberEqualTo(uuid);
		example.or(criteria);
		int totalCount=new B_T_Ufp_PaymentServiceImpl().count(example,b_T_Ufp_PaymentMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		List<B_T_Ufp_Payment> b_T_Ufp_Payment= (List<B_T_Ufp_Payment>) b_T_Ufp_PaymentMapper.selectByExample(example);
		pager.setPageRecords(b_T_Ufp_Payment);
		return  pager;
	}

	public Pager<B_T_Ufp_Payment> selectList(B_T_Ufp_Payment b_T_Ufp_Payment,Pager<B_T_Ufp_Payment> pager,String uuid) {
		B_T_Ufp_PaymentExample example=new B_T_Ufp_PaymentExample();
		cn.maszy.model.contract.B_T_Ufp_PaymentExample.Criteria criteria = example.createCriteria();
		if(!"".equals(uuid)){
			criteria.andSerialnumberEqualTo(uuid);
		}
		example.or(criteria);
		int totalCount=new B_T_Ufp_PaymentServiceImpl().count(example,b_T_Ufp_PaymentMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		List<B_T_Ufp_Payment> list= (List<B_T_Ufp_Payment>) b_T_Ufp_PaymentMapper.selectByExample(example);
		pager.setPageRecords(list);
		return  pager;
	}

	public int delete(String checkIds) {
		for (String id : checkIds.split(", ")) {
			b_T_Ufp_PaymentMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	public int count(B_T_Ufp_PaymentExample example, B_T_Ufp_PaymentMapper b_T_Ufp_PaymentMapper) {
		// TODO Auto-generated method stub
		return b_T_Ufp_PaymentMapper.countByExample(example);
	}

}
